<template>
<div class="login">
    <el-row >
      <el-col :span="24">
        <div class="login-form">
          <h1 class="loginfont">登录</h1>
          <el-form ref="form" :model="user" label-width="80px">
            <el-form-item class="input" label="用户名">
              <el-input v-model="user.username" type="username"></el-input>
            </el-form-item>
            <el-form-item class="input" label="密码">
              <el-input v-model="user.password" type="password"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button class="primary" type="primary" @click="login">登录</el-button>
              <el-button>取消</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-col>
    </el-row>
</div>
</template>

<script>
import axios from "axios";

export default {
  name: "login",
  data() {
    return {
      user: {
        username: '',
        password: ''
      }
    }
  },methods: {
    login(){
      console.log(this.user)
      axios.post('/login',this.user).then(res=>{
        if(res.data.code===200){
          this.$message.success('登录成功')
          this.$store.commit('setToken',res.data.data)
          console.log(res.data.data)
          this.$store.commit('setUsername',this.user.username)

          this.$router.push('/home')
        }else{
          console.log(res.data.msg)
          this.$message.error(res.data.msg)
        }
      })
    }
  }
  };
</script>

<style scoped>
/* 重置默认边距 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.login {
  height: 100vh;
  width: 100vw;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-image: url("../assets/loginback.png");
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

.login-form {
  background-color: rgba(221, 233, 229, 0.88); /* 淡灰色背景，带透明度 */
  padding: 30px;
  border-radius: 8px;
  box-shadow: 0 0 10px rgba(221, 233, 229, 0.32);
  width: 100%;
}
.loginfont{
  color: rgb(95, 97, 101);
  font-size: 30px;
  font-weight: bold;
  text-align: center;
  margin-bottom: 20px;
}
.input{
  font-size: 20px;
  font-weight: bold;
  text-align: center;
  margin-bottom: 20px;
}

.primary{
  background-color: #4BFF8A; /* 蓝色背景 */
  color: #ffffff; /* 白色文字 */
  border: none; /* 去掉边框 */
}
.primary:hover{
  background-color: #E6E34D; /* 鼠标悬停时背景色变浅 */
}


/* Element UI 样式覆盖 */
.el-form {
  margin-top: 20px;
}

.el-input {
  margin-bottom: 10px;
}

.el-button {
  margin-right: 10px;
}
</style>
